package de.smarthome.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import de.smarthome.R;
import de.smarthome.szenario.ScenarioData;

public class InfoScreenAdapter extends BaseAdapter {

	private final List<ScenarioData> objects;
	private final LayoutInflater inflater;

	public InfoScreenAdapter(Activity context, List<ScenarioData> objects) {
		this.objects = objects;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return objects.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View itemView = convertView;
		ScenarioData item = this.objects.get(position);

		if (itemView == null)
			itemView = this.inflater.inflate(R.layout.item_infoscreen, null);

		TextView room = (TextView) itemView.findViewById(R.id.roomTitle);
		room.setText(item.getRoomName());

		TextView light = (TextView) itemView.findViewById(R.id.lightItem);
		light.setText(item.getLightStatus());

		LinearLayout color = (LinearLayout) itemView
				.findViewById(R.id.colorField);
		color.setBackgroundColor(item.getColor());

		TextView window = (TextView) itemView.findViewById(R.id.windowItem);
		window.setText(item.getWindowStatus());

		TextView curtain = (TextView) itemView.findViewById(R.id.curtainItem);
		curtain.setText(item.getCurtainStatus());

		TextView blind = (TextView) itemView.findViewById(R.id.blindItem);
		blind.setText(item.getBlindStatus());

		TextView heater = (TextView) itemView.findViewById(R.id.heaterItem);
		heater.setText(item.getHeaterStatus());

		return itemView;
	}
}
